package com.sky.service.impl;

import com.sky.constant.MessageConstant;
import com.sky.constant.RedisConstant;
import com.sky.result.Result;
import com.sky.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ShopServiceImpl implements ShopService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public Result queryStatus() {
        String status = stringRedisTemplate.opsForValue().get(RedisConstant.SHOP_STATUS);
        if (status == null) {
            return Result.error(MessageConstant.SHOP_STATUS);
        }
        return Result.success(status);
    }

    @Override
    public Result setShopStatus(Integer status) {
        stringRedisTemplate.opsForValue().set(RedisConstant.SHOP_STATUS, String.valueOf(status));
        return Result.success();
    }
}
